package edu.csumb.itcd.teammario;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;

public class PoisonBullet extends Bullet {

	private Poison poisonType = new Poison(1,5);
	
	public PoisonBullet(Point2D start, Point2D destination, int damage, int range, Poison poison)
	{
		super(start, destination, damage, range);
        if (isActive != true){
            
        	 
        	this.damage = damage;
            this.range = range;
            speed = 11;
            bulletDiameter = 10;
            poisonType = poison;
            
            bulletPosition = new Point2D.Double(start.getX(), start.getY());
            
            vectorY = destination.getY() - (bulletDiameter/2) - start.getY();
            vectorX = destination.getX() - (bulletDiameter/2) - start.getX();

            //The dist variables need to be positive for the trig equations.
            distY = Math.abs(vectorY);
            distX = Math.abs(vectorX);

            //Gives the vectors a value of 1 or -1.
            vectorY /= distY;
            vectorX /= distX;

            /**
             * tan(x) = opposite/adjacent
             * tan(x) = distY/distX
             * x = arctan(distY/distX)
             *
             * cos(x) = adjacent/hypotenuse
             * cos(x) = moveX/speed
             * moveX = speed * cos(x)
             * moveX = speed * cos(arctan(distY/distX))
             */
            if (distX == 0)
            {
                moveY = speed;
                moveX = 0;
            } else
            {
                moveY = speed * Math.sin(Math.atan(distY/distX));
                moveX = speed * Math.cos(Math.atan(distY/distX));
                moveY = moveY * vectorY;
                moveX = moveX * vectorX;
            }
          
            isActive = true;
        }
	}
	
	public void enemyOnHit(Enemy enemy)
	{
		//System.out.println("enemy hit with poison bullet");
		enemy.setPoisonReceived(poisonType);
	}
	
	@Override
	public void playerOnHit()
	{
	//	System.out.println("player hit with poison");
		Player.setPoisonReceived(poisonType);
	}
	public void paintBullet(Graphics2D g2)
	 {
		 if (isActive == true)
	     {
			 g2.setColor(Color.GREEN);
			 Ellipse2D bulletImage = new Ellipse2D.Double(bulletPosition.getX(), bulletPosition.getY(), bulletDiameter, bulletDiameter);
			 g2.fill(bulletImage);
	     }
	 }
	
}
